package us.mooresr.webtroopmanager.client.ui;

import us.mooresr.webtroopmanager.client.place.LoginPlace;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ValidationViewImpl extends Composite implements ValidationView {
	Presenter presenter;

	private static ValidationViewImplUiBinder uiBinder = GWT
			.create(ValidationViewImplUiBinder.class);

	interface ValidationViewImplUiBinder extends
			UiBinder<Widget, ValidationViewImpl> {
	}
	
	@UiField
	Label statusLabel;
	
	@UiField
	Button cancelButton;
	
	@UiHandler("cancelButton") 
	void onCancelButton(ClickEvent e) {
		presenter.goTo(new LoginPlace());
	}

	public ValidationViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
		
	}

	@Override
	public void updateSuccess(Boolean success) {
		if (success) {
			statusLabel.setText("Registration validated.");
			cancelButton.setText("OK");
		} else {
			statusLabel.setText("Unable to validate your registration.  Please check your validation key.");
			cancelButton.setText("OK");
		}
		
	}

}
